package com.sinoglobal.ningxia.activity.mico;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Process;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.alipay.sdk.util.LogUtils;
import com.baidu.cyberplayer.core.BVideoView;
import com.baidu.cyberplayer.core.BVideoView.OnCompletionListener;
import com.baidu.cyberplayer.core.BVideoView.OnCompletionWithParamListener;
import com.baidu.cyberplayer.core.BVideoView.OnErrorListener;
import com.baidu.cyberplayer.core.BVideoView.OnInfoListener;
import com.baidu.cyberplayer.core.BVideoView.OnPlayingBufferCacheListener;
import com.baidu.cyberplayer.core.BVideoView.OnPreparedListener;
import com.baidu.cyberplayer.utils.VersionManager;
import com.baidu.cyberplayer.utils.VersionManager.CPU_TYPE;
import com.baidu.cyberplayer.utils.VersionManager.RequestCpuTypeAndFeatureCallback;
import com.baidu.cyberplayer.utils.VersionManager.RequestDownloadUrlForCurrentVersionCallback;
import com.baidu.cyberplayer.utils.ZipUtils;
import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.adapter.PlayBillAdapter;
import com.sinoglobal.ningxia.beans.BroadCastBean;
import com.sinoglobal.ningxia.beans.BroadCastVo;
import com.sinoglobal.ningxia.beans.PlayBillBean;
import com.sinoglobal.ningxia.downdata.imp.RemoteImpl;
import com.sinoglobal.ningxia.frame.FlyApplication;
import com.sinoglobal.ningxia.frame.ShareAbstractActivity;
import com.sinoglobal.ningxia.http.Code;
import com.sinoglobal.ningxia.http.ConnectionUtil;
import com.sinoglobal.ningxia.service.RadioService;
import com.sinoglobal.ningxia.utils.SharedPreferenceUtil;
import com.sinoglobal.ningxia.utils.TextUtil;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;

import java.io.File;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/**
 * 
 * @title: BroadCastActivity.java
 * @package com.sinoglobal.ningxia.activity.mico
 * @description: 广播页
 * @author qiwx
 * @date 2014-6-25 下午5:11:52
 */
public class BroadCastActivity extends ShareAbstractActivity implements OnClickListener, OnPreparedListener, OnCompletionListener,
		OnErrorListener, OnInfoListener, OnPlayingBufferCacheListener, OnCompletionWithParamListener {
	private PopupWindow pow;// 功能菜单
	private LinearLayout popwindowView;
	private LinearLayout share;// 分享功能
	private LinearLayout collect;// 收藏功能
	private TextView topView;
	private ImageView btnMenu; // 节目单
	private ImageView btnPre;// 上一个频道
	private ImageView btnNext;// 下一个频道
	private PopupWindow powBill;// 广播节目单
	private View view;// 广播节目单
	private PlayBillAdapter adapter;
	private ListView playList;
	private int popWidth1;
	private int popHeith1;
	private int popWidth2;
	private int popHeith2;
	private AsyncTask<Void, Void, BroadCastVo> mTask;// 加载网络数据
	private List<BroadCastBean> ChannelData;// 广播频道列表
	private Activity activity;
	private ProgressBar pb;
	Intent radioService;
	private int position;// 播放index;
	private TextView radioName;// 广播栏目名称
	private TextView stationName;// 广播频道名称
	private TextView stationHz;// 频率
	// private final String RADIO_BILL = "com.radio.bill";// 监听系统时间来调整节目单
	private long currentTime;// 当前时间
	private List<PlayBillBean> list;// 节目单
	private String Str_Name = "";// 节目名称
	private boolean isRun = true;
	private int startType;// 播放fan
	private String FLAG = "flag";// 1代表解码播放，2代表webView播放
	// m3U8格式视频
	public static String AK = "mgULe96W4RVjCyDXviEtbaUA";
	public static String SK = "Z0dhKEeGq0yoG7Vu";
	public static String TAG = "video";
	int radio_position = 0;

	// 播放状态
	private enum PLAYER_STATUS {
		PLAYER_IDLE, PLAYER_PREPARING, PLAYER_PREPARED,
	}

	// 初始状态
	private PLAYER_STATUS mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;
	// 视频播放类
	private BVideoView mVV = null;
	// 视频状态控制
	private EventHandler mEventHandler;
	private HandlerThread mHandlerThread;

	private final Object SYNC_Playing = new Object();
	// wakelock是一种锁的机制, 只要有task拿着这个锁, 系统就无法进入休眠，使用完及时释放掉锁
	private WakeLock mWakeLock = null;
	private static final String POWER_LOCK = "VideoViewPlayingActivity";
	// 解码模式，分为硬解码与软解码
	private boolean mIsHwDecode = false;

	private final int EVENT_PLAY = 0;
	private final int UI_EVENT_UPDATE_CURRPOSITION = 1;
	private final int UI_PROGRESS_VISEIBLE = 2;
	private final int UI_PROGRESS_GOEN = 3;
	private final int SO_FINISHED = 4;// so 库下载完成
	private final int SO_FIALED = 5;// so库下载失败;

	// so文件存放目录
	private String libsPath = "/data/data/";
	// 下载百度播放器需要的so文件
	FinalHttp ft;
	private String mVideoSource = null;
	private ExecutorService executorService;// 线程池
	private RaidoReceiver recevier;
	static RThread rt;
	private MHandler mHandler;
	// DialogBuilder builder;
	AlertDialog mdialog;
//	TextView tv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		executorService = Executors.newFixedThreadPool(5);
		recevier = new RaidoReceiver();
		
		mHandler = new MHandler();
		rt = new RThread();
		mdialog = new AlertDialog.Builder(this).create();

		mdialog.setTitle("首次使用广播初始化中，请稍等...");
		/*
		 * tv = new TextView(this); tv.setText("首次使用广播初始化中，请稍等...");
		 * tv.setTextSize(12); mdialog.setContentView(tv);
		 */
		activity = this;
		setContentView(R.layout.broadcast_activity);
		openChenJInShi();//开启沉浸式
		// 节目单
		view = LayoutInflater.from(this).inflate(R.layout.play_bill_fragment, null);
		// 开启后台事件处理线程
		mHandlerThread = new HandlerThread("event handler thread", Process.THREAD_PRIORITY_BACKGROUND);
		mHandlerThread.start();
		mEventHandler = new EventHandler(mHandlerThread.getLooper());
		init();
		loadData();
	}

	private void init() {
		libsPath = libsPath + getApplication().getPackageName() + "/";
		PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, POWER_LOCK);
		mIsHwDecode = getIntent().getBooleanExtra("isHW", false);
		ft = new FinalHttp();
		Intent get = getIntent();
		startType = get.getIntExtra(FLAG, 0);
		radioService = new Intent(BroadCastActivity.this, RadioService.class);
		stationName = (TextView) findViewById(R.id.stationName);
		radioName = (TextView) findViewById(R.id.radioName);
		stationHz = (TextView) findViewById(R.id.stationHz);
		pb = (ProgressBar) findViewById(R.id.radioPb);
		topView = (TextView) findViewById(R.id.topview);
		playList = (ListView) view.findViewById(R.id.playBillListView);
		titleView.setText(R.string.broadCast);
		microButtonRight.setVisibility(View.VISIBLE);
		microButtonRight.setImageResource(R.drawable.top_actionbar_bg);
		microButtonRight.setOnClickListener(this);
		templateButtonLeft.setOnClickListener(this);
		btnMenu = (ImageView) findViewById(R.id.radioMenu);
		btnMenu.setOnClickListener(this);
		btnPre = (ImageView) findViewById(R.id.radioPrevious);
		btnPre.setOnClickListener(this);
		btnNext = (ImageView) findViewById(R.id.radioNext);
		btnNext.setOnClickListener(this);

	}

	Handler mUIHandler = new Handler() {
		@SuppressLint("NewApi")
		public void handleMessage(Message msg) {
			switch (msg.what) {
			// 更新进度及时间
			case UI_EVENT_UPDATE_CURRPOSITION:
				// LogUtil.i(TAG, currPosition + "----当前进度位置----");
				mUIHandler.sendEmptyMessageDelayed(UI_EVENT_UPDATE_CURRPOSITION, 200);
				if (pb.getVisibility() == View.VISIBLE) {
					pb.setVisibility(View.GONE);
				}
				break;
			//
			case UI_PROGRESS_VISEIBLE:
				pb.setVisibility(View.VISIBLE);
				break;
			case UI_PROGRESS_GOEN:
				pb.setVisibility(View.GONE);
				break;
			case SO_FIALED:
				showShortToastMessage("更新视频载库失败");
				finish();
				break;
			case SO_FINISHED:
				String dataUrl = (String) msg.getData().get("url");
				String name = dataUrl.substring(dataUrl.lastIndexOf("/") + 1, dataUrl.indexOf("?"));
				Log.e(TAG, name + "----");
				String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + name;

				ft.download(dataUrl, path, new AjaxCallBack<File>() {
					@Override
					public void onLoading(long count, long current) {
						super.onLoading(count, current);
						Log.e(TAG, current + "下载进度" + "so文件大小" + count);
					}

					@Override
					public void onStart() {
						super.onStart();
						Log.e(TAG, "开始下载");
						mdialog.show();
						mdialog.setCancelable(false);
					}

					@Override
					public void onSuccess(File file) {
						super.onSuccess(file);
						String filePath = file.getAbsolutePath();
						Log.e(TAG, "so下载完成");
						mdialog.dismiss();
						try {
							String fileName = file.getName();
							if (fileName.contains(".zip"))
								fileName = fileName.replace(".zip", "");
							ZipUtils.getInstance().unZip(getApplicationContext(), filePath, libsPath);
							SharedPreferenceUtil.saveBoolean(BroadCastActivity.this, "SO_FINISH", true);
							initVideo();
							mEventHandler.sendEmptyMessage(EVENT_PLAY);
						} catch (Exception e) {
							e.printStackTrace();
							Log.e(TAG, "下载so异常信息：" + e.toString());
						}
					}

					@Override
					public void onFailure(Throwable t, int errorNo, String strMsg) {

						super.onFailure(t, errorNo,strMsg);
						mdialog.dismiss();
					}

				});

				break;

			default:
				break;
			}
		}
	};

	private void initVideo() {
		// 设置ak及sk的前16位
		BVideoView.setAKSK(AK, SK);
		BVideoView.setNativeLibsDirectory(libsPath);
		// 获取BVideoView对象
		mVV = (BVideoView) findViewById(R.id.video_view);

		mVV.setOnClickListener(this);
		// 注册listener
		mVV.setOnPreparedListener(this);
		mVV.setOnCompletionListener(this);
		// 视频播放完成走的接口
		mVV.setOnCompletionWithParamListener(this);
		mVV.setOnErrorListener(this);
		mVV.setOnInfoListener(this);
		mVV.setOnPlayingBufferCacheListener(this);
		// mVV.setLogLevel(10);
		// 设置解码模式
		mVV.setDecodeMode(mIsHwDecode ? BVideoView.DECODE_HW : BVideoView.DECODE_SW);
	}

	class EventHandler extends Handler {
		public EventHandler(Looper looper) {
			super(looper);
		}

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case EVENT_PLAY:
				// 如果已经播放了，等待上一次播放结束
				if (mPlayerStatus != PLAYER_STATUS.PLAYER_IDLE) {
					synchronized (SYNC_Playing) {
						try {
							SYNC_Playing.wait();
							LogUtils.e("wait player status to idle");
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
				// 设置播放url
				mVV.setVideoPath(mVideoSource);
				// 显示或者隐藏缓冲提示,false隐藏，自己处理进度条
				mVV.showCacheInfo(false);
				// 开始播放
				mVV.start();
				mPlayerStatus = PLAYER_STATUS.PLAYER_PREPARING;
				break;
			default:
				break;
			}
		}
	}

	// 加载广播信息
	private void loadData() {

		mTask = new ItktAsyncTaskWithDialog<Void, Void, BroadCastVo>(getString(R.string.loading), true, true) {

			@Override
			public BroadCastVo before(Void... params) throws Exception {
				return RemoteImpl.getInstance().getBroadCastInfo();
			}

			@Override
			public void after(BroadCastVo result) {
				if (result == null)
					return;
				if (result.getCode() == Code.CODE_SUCCESS) {
					ChannelData = result.getChannel_list();
				}
				if (ChannelData == null || ChannelData.size() == 0)
					return;
				BroadCastBean bean = ChannelData.get(0);
				mVideoSource = bean.getNx_radio_url();
				try {
					updateInfo(0);
				} catch (Exception e) {
					// myTask Auto-generated catch block
					e.printStackTrace();
				}
				list = bean.getList();
				setData(bean.getChannel_id(), list);
				getCpuSo();
				// mEventHandler.sendEmptyMessage(EVENT_PLAY);

			}

			@Override
			public void exception() {

			}
		};
		mTask.execute();
	}

	public void getCpuSo() {

		// String path = libsPath + "libcyberplayer.so";
		pb.setVisibility(View.VISIBLE);
		// File file = new File(path);
		boolean is_finish = SharedPreferenceUtil.getBoolean(BroadCastActivity.this, "SO_FINISH");
		if (is_finish) {
			initVideo();
			mEventHandler.sendEmptyMessage(EVENT_PLAY);
			return;
		}

		// 先判断CPU类型
		VersionManager.getInstance().getCurrentSystemCpuTypeAndFeature(5000, AK, SK, new RequestCpuTypeAndFeatureCallback() {
			@Override
			public void onComplete(CPU_TYPE type, int arg1) {
				VersionManager.getInstance().getDownloadUrlForCurrentVersion(5000, type, AK, SK,
						new RequestDownloadUrlForCurrentVersionCallback() {
							@Override
							public void onComplete(String url, int arg1) {
								Log.e(TAG, "cpu so 库文件" + url);

								if (url == null || url.length() <= 0) {
									Message msg = new Message();
									msg.what = SO_FIALED;
									mUIHandler.sendMessage(msg);
									return;
								}
								Message msg = new Message();
								msg.what = SO_FINISHED;
								Bundle bundler = new Bundle();
								bundler.putString("url", url);
								msg.setData(bundler);
								mUIHandler.sendMessage(msg);
							}
						});

			}
		});
	}

	private void setData(String channelId, List<PlayBillBean> data) {

		adapter = new PlayBillAdapter(this, data, false);
		playList.setPadding(0, 0, 0, 20);
		playList.setAdapter(adapter);

	}

	// 分享菜单的popwindow
	private void setUpPop(PopupWindow pop, int width, int height) {

		pop.setWidth(width);
		pop.setHeight(height);
		// 实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(+R.color.half_transparent);
		// 需要设置一下此参数，点击外边可消失
		pop.setBackgroundDrawable(dw);
		// 设置点击窗口外边窗口消失
		pop.setOutsideTouchable(true);
		// 设置此参数获得焦点，否则无法点击
		pop.setFocusable(true);
		pop.setOnDismissListener(new OnDismissListener() {
			@Override
			public void onDismiss() {

			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.mico_but_right: // 顶部右侧功能键，收藏功能去掉，只有分享
			if (pow == null) {
				pow = new PopupWindow(BroadCastActivity.this);
				popwindowView = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.program_fuction_menu, null);
				share = (LinearLayout) popwindowView.findViewById(R.id.share);
				share.setOnClickListener(this);
				collect = (LinearLayout) popwindowView.findViewById(R.id.collect);
				collect.setVisibility(View.GONE);
				pow.setContentView(popwindowView);
				popWidth1 = FlyApplication.widthPixels / 4;
				popHeith1 = 2 * popWidth1 / 3;
				setUpPop(pow, popWidth1, popHeith1);
			}
			pow.showAsDropDown(topView);
			break;
		case R.id.share:// 分享
			/*
			 * String share =
			 * getResources().getString(R.string.radio_share_content); try {
			 * String radio = ChannelData.get(position).getChannel_name(); if
			 * (TextUtil.stringIsNotNull(Str_Name)) radio = radio + "——" +
			 * Str_Name + "栏目"; share = share.replace("radio", radio); } catch
			 * (Exception e) { e.printStackTrace(); share =
			 * share.replace("《radio》", ""); }
			 */
			String share;
			try {
				share = ChannelData.get(position).getFengxiang();
				if (TextUtil.stringIsNull(share))
					share = "分享";
			} catch (Exception e) {
				e.printStackTrace();
				share = "分享";
			}
			showPopwindow(true, share, null, ConnectionUtil.MicDoorAdress);
			break;
		case R.id.radioMenu:// 点击节目单图标
			if (ChannelData == null || ChannelData.size() == 0)
				showShortToastMessage(activity.getResources().getString(R.string.noPlayBill));
			else {
				if (powBill == null) {
					powBill = new PopupWindow(BroadCastActivity.this);
					popWidth2 = FlyApplication.widthPixels - 40; // 广播节目单
					popHeith2 = FlyApplication.heightPixels / 2;// 广播单高度，底部View高度是110
					// margin=
					// (FlyApplication.heightPixels/2-126)-popHeith2/2;//计算节目表距离底部view的位置
					setUpPop(powBill, popWidth2, popHeith2);
					view.invalidate();
					powBill.setContentView(view);
					powBill.setBackgroundDrawable(getResources().getDrawable(R.drawable.broadcast_bill_bg));
				}
				powBill.showAsDropDown(btnMenu, 0, 0);
				pb.setVisibility(View.GONE);
			}
			break;
		case R.id.radioPrevious:// 上一个节目
			if (ChannelData == null || ChannelData.isEmpty())
				return;
			if (mPlayerStatus != PLAYER_STATUS.PLAYER_IDLE) {
				mVV.stopPlayback();
			} //
				// 发起一次新的播放任务，测试固定url
			if (radio_position <= 0) {
				radio_position = ChannelData.size() - 1;
			} else {
				radio_position--;
			}
			try {
				updateInfo(radio_position);

			} catch (Exception e) {
				// myTask Auto-generated catch block
				e.printStackTrace();
			}
			mVideoSource = ChannelData.get(radio_position).getNx_radio_url();
			if (mEventHandler.hasMessages(EVENT_PLAY))
				mEventHandler.removeMessages(EVENT_PLAY);
			mEventHandler.sendEmptyMessage(EVENT_PLAY);
			break;
		case R.id.radioNext:// 下一个节目
			if (ChannelData == null || ChannelData.isEmpty())
				return;
			if (mPlayerStatus != PLAYER_STATUS.PLAYER_IDLE) {
				mVV.stopPlayback();
			}
			if (radio_position >= ChannelData.size() - 1) {
				radio_position = 0;
			} else {
				radio_position++;
			}
			try {
				updateInfo(radio_position);

			} catch (Exception e) {
				// myTask Auto-generated catch block
				e.printStackTrace();
			}
			mVideoSource = ChannelData.get(radio_position).getNx_radio_url();
			if (mEventHandler.hasMessages(EVENT_PLAY))
				mEventHandler.removeMessages(EVENT_PLAY);
			mEventHandler.sendEmptyMessage(EVENT_PLAY);
			break;

		case R.id.title_but_left:
			finish();
			break;
		}

	}

	@Override
	protected void onPause() {
		// myTask Auto-generated method stub
		super.onPause();
		if (mVV != null && mVV.isPlaying()) {
			mVV.pause();
		}
		// 及时释放资源
		if (mWakeLock != null)
			mWakeLock.release();

	}
	

	@Override
	protected void onResume() {
		// myTask Auto-generated method stub
		super.onResume();
		// 监听系统时间,每分钟监听一次
		IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
	
		registerReceiver(recevier, filter);
		if (null != mWakeLock && (!mWakeLock.isHeld())) {
			mWakeLock.acquire();
		}
	}

	@Override
	protected void onStop() {
		super.onStop();
		unregisterReceiver(recevier);
	}

	// 查找当前radio名称
	private void findRadioName() {
		executorService.submit(new Runnable() {

			public void run() {
				Log.e(TAG, "监听时间");
				currentTime = System.currentTimeMillis() / 1000;
				if (list == null || list.isEmpty())
					return;
				int len = list.size();
				for (int i = 0; i < len; i++) {
					PlayBillBean bean = list.get(i);
					if (currentTime > Long.valueOf(bean.getPlay_time()) && currentTime < Long.valueOf(bean.getEnd_time())) {
						Str_Name = bean.getJiemuname();
						mHandler.sendEmptyMessage(1);
						break;
					}

				}
			}
		});
	}

	// 监听节目单
	public class RaidoReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
				try {
					rt.notify();
				} catch (Exception e) {
					e.printStackTrace();
				}
				findRadioName();
			}

		}
	}

	class RThread extends Thread {
		public void run() {
			try {
				synchronized (this) {
					while (isRun) {
						currentTime = System.currentTimeMillis() % 1000;
						if (list == null || list.isEmpty())
							return;
						int len = list.size();
						for (int i = 0; i < len; i++) {
							PlayBillBean bean = list.get(i);
							if (Long.valueOf(bean.getPlay_time()) < currentTime && Long.valueOf(bean.getEnd_time()) > currentTime) {
								Str_Name = bean.getJiemuname();
								mHandler.sendEmptyMessage(1);
								break;
							}
						}
						wait();
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

	}

	class MHandler extends Handler {
		@Override
		public void dispatchMessage(Message msg) {
			super.dispatchMessage(msg);
			switch (msg.what) {
			case 1:
				radioName.setText(Str_Name);
				break;
			}

		}
	}

	@Override
	protected void onRestart() {
		// myTask Auto-generated method stub
		super.onRestart();
		if (mEventHandler.hasMessages(EVENT_PLAY))
			mEventHandler.removeMessages(EVENT_PLAY);
		mEventHandler.sendEmptyMessage(EVENT_PLAY);
	}

	// 更新频道信息
	private void updateInfo(int position) throws Exception {
		stationHz.setText(ChannelData.get(position).getRadio_hz());
		stationName.setText(ChannelData.get(position).getChannel_name());
		list = ChannelData.get(radio_position).getList();
		setData("DD", list);
		try {
			rt.notify();
		} catch (Exception e) {
			e.printStackTrace();
		}
		findRadioName();
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			finish();
			return true;
		}
		return false;

	}

	@Override
	public void OnCompletionWithParam(int arg0) {
		// myTask Auto-generated method stub

	}

	@Override
	public void onPlayingBufferCache(int arg0) {
		// myTask Auto-generated method stub

	}

	@Override
	public boolean onInfo(int what, int extra) {
		switch (what) {
		// 开始缓冲
		case BVideoView.MEDIA_INFO_BUFFERING_START:
			mUIHandler.sendEmptyMessage(UI_PROGRESS_VISEIBLE);
			break;
		// 结束缓冲
		case BVideoView.MEDIA_INFO_BUFFERING_END:
			mUIHandler.sendEmptyMessage(UI_PROGRESS_GOEN);
			break;
		default:
			break;
		}
		return true;
	}

	@Override
	public boolean onError(int arg0, int arg1) {
		synchronized (SYNC_Playing) {
			SYNC_Playing.notify();
		}
		mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;
		mUIHandler.removeMessages(UI_EVENT_UPDATE_CURRPOSITION);
		return true;
	}

	@Override
	public void onCompletion() {
		synchronized (SYNC_Playing) {
			SYNC_Playing.notify();
		}
		mPlayerStatus = PLAYER_STATUS.PLAYER_IDLE;

		mUIHandler.removeMessages(UI_EVENT_UPDATE_CURRPOSITION);

	}

	@Override
	public void onPrepared() {
		mUIHandler.sendEmptyMessage(UI_PROGRESS_GOEN);
		mPlayerStatus = PLAYER_STATUS.PLAYER_PREPARED;
		mUIHandler.sendEmptyMessage(UI_EVENT_UPDATE_CURRPOSITION);

	}
}
